package com.ftg.learn.chapter08;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @author kangjx
 * @createTime 2022/7/19
 */
public class MyUnion {



    //交集  [两个多个数组当中，内容相同的元素]  内连
    //并集  [直接全并两个或者多个数组]  [去掉重复]  全连
    //差集  [左差集 左连  右差集  右连  两侧差集 ]

    public static void main(String[] args) {

        int[] as = new int[]{2,4,1,0,7};
//    ------------------------
        int[] as1 = new int[]{5,0,1,4};
        //Arrays
        int[] result = Arrays.copyOf(as,as.length+as1.length);

        //。。。
        System.arraycopy(as1,0,result,as.length,as1.length);

        //并集  全集
        System.out.println(Arrays.toString(result));

        //去掉重复
       int[] as2 = new int[]{1,2,1,1,14,5,6};
        System.arraycopy(as2,2,as2,1,as2.length-2);
        System.out.println(Arrays.toString(Arrays.copyOf(as2,as2.length-1)));

        for(int i = 0 ;i < as2.length;i++){

                for(int j = as2.length-1;j>=i+1;j--){
                    if(  as2[i] == as2[j]){

                    }
                }
        }

    }

    public void q1(){
        int[] as = new int[]{2,4,1,0};
        System.out.println(as);
//    ------------------------
        int[] as1 = new int[]{5,0,1,4};

        System.out.println("交集");

        //4,1,0,null
        Integer[] result = new Integer[Math.min(as.length,as1.length)];

        int index = 0;
        for(int i = 0 ,len = as.length;i < len;i++){

            for(int j = 0 ,jlen = as1.length;j < jlen;j++){
                if(as[i] == as1[j]){
                    result[index++] = as[i];
                    break;
                }
            }
        }

        int sum = 0;
        for(int i = 0;i < result.length;i++){
            if(result[i] != null){
                sum++;
            }
        }

        //对指定数组进行拷贝操作（数组，长度）
        Integer[] rs = Arrays.copyOf(result,sum);
        //对可自然排序的数组进行排序
        Arrays.sort(rs);

        //把数组转换成为字符串直接输出
        System.out.println(Arrays.toString(rs));
        //Arrays Math
    }



}
